﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ActivityLog : MonoBehaviour 
{
  // holds the strings for that are show in the log window
  private Queue<string> EventLog = new Queue<string>();

  //place holder string for the log window
  private string logGuiText = "";

  //sets the size of the log window
  private Rect logWindow = new Rect(0, Screen.height - (Screen.height / 3), Screen.width - (Screen.width / 3), Screen.height / 3);



  //sets the maximum number of lines that will be displayed in the log window
  public int maxLines = 10;

  

  void OnGUI()
  {
    //creates the log window
    GUI.Window(0, logWindow, LogWindow, "Activity Log");
  }
  void LogWindow(int windoId)
  {
    //closes the log window
    GUI.Button(new Rect(logWindow.width - 100, 0, 100, 25), "Close");

    GUI.Label(new Rect(0, 0, 1000, 10000), logGuiText);
  }

  public void AddEvent(string eventString)
  {
    //removes the oldest entry in the log window and scrolls up the rest of the lines
    if (EventLog.Count >= maxLines)
    {
      EventLog.Dequeue();
    }

    //ands in the lastest string set to the Queue
    EventLog.Enqueue(eventString);
    logGuiText = "";

    //places the new string in logEvent and starts a new line
    foreach (string logEvent in EventLog)
    {
      logGuiText += logEvent;
      logGuiText += "\n";
    }
  }


}
